package net.sevear.chaos.view
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	
	import mx.core.UIComponent;
	
	public class LoadingBar extends UIComponent
	{
		[Embed(source='/res/unloadedbg.png')]
		private var unloadCls:Class;
		[Embed(source='/res/loadedbg2.png')]
		private var loadedCls:Class;
		
		private var unloadBmd:BitmapData;
		private var loadedBmd:BitmapData;
		public function LoadingBar()
		{
			super();
			this.height = 10;
			var cls:Class = unloadCls;
			unloadBmd = ((new cls()) as Bitmap).bitmapData;
			cls = loadedCls;
			loadedBmd = ((new cls()) as Bitmap).bitmapData;
		}
		
		private var _p:Number;
		public function drawPerc(percent:Number):void{
			_p = percent;
			this.graphics.clear();
			this.graphics.beginBitmapFill(loadedBmd);
			this.graphics.drawRect(0,0,percent*this.width,this.height);
			this.graphics.beginBitmapFill(unloadBmd);
			this.graphics.drawRect((percent)*width,0,(1-percent)*width,height);
			this.graphics.endFill();
		}
		
		public function get percent():Number{
			return _p;
		}
	}
}